﻿#ifndef TM_SSHCONNECTWGT_H
#define TM_SSHCONNECTWGT_H

#include <QDialog>
#include <QFont>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QRegExp>
#include <QRegExpValidator>
#include <QTextBrowser>
#include <QMessageBox>
#include <QTableWidget>
#include <QProgressDialog>

#include "ssh.h"
#include "common.h"

#include "securefileuploader.h"

#include <QUdpSocket>

class TM_SSHConnectWGT : public QDialog
{
    Q_OBJECT
public:
    TM_SSHConnectWGT();
    ~TM_SSHConnectWGT();

signals:
    /**
     * @brief sigSend   发送指令
     * @param cmd       指令
     */
    void sigSend(QString cmd);

    /**
     * @brief sigDisconnected  断开 SSH 连接
     */
    void sigDisconnected();


    void sigPush(const QString &localFile, const QString &dest, const QString &host,
                 const QString &username, const QString &passwd,const int &port);//文件推送
    void sigPull(const QString &remoteFilePath, const QString &dest, const QString &host,
                 const QString &username, const QString &passwd, const int &port);//文件拉取

    void sig_TcpCmdData(QString Type,QString data);
public slots:
    /**
     * @brief connectStateChanged           SSH 连接状态改变
     * @param state                         true: 连接,  false: 断开
     * @param ip                            IP 地址
     * @param port                          端口号
     */
    void connectStateChanged(bool state, QString ip, int port);

    /**
     * @brief dataArrived                   执行指令输出
     * @param msg                           信息
     * @param ip                            IP 地址
     * @param port                          端口号
     */
    void dataArrived(QString msg, QString ip, int port);

    /**
     * @brief sshConnect                    快速连接/断开
     */
    void sshConnect();

    /**
     * @brief executeCmd                    执行指令
     */
    void executeCmd();

    void Pub_executeCmd(QString cmdStr);

    void Public_ssh_Push(QString mapID);
    void Public_ssh_Pull(QString mapID,QString type = "");

    void Public_ssh_PullFilePath(QString path);
    void Public_ssh_PushFilePath(QString path);

    void clearText();

public slots:
    void sshPush(QString MapID = "");
    void sshPull(QString MapID = "");

    void slot_rebootClick();

    void slot_QSSH_Data(QString Type,QString path);

    void slot_SSH_Transfer(QString filePath,bool Statu);

    void slot_TcpConnectStatu(bool statu);

    void slot_udpReceive();

    void slot_doubleClickItem(QTableWidgetItem *item);
private:
    QString m_RemoteMapNameStr = "";

    QString m_pushMapName = "";
    QString m_pullType = "";
    QUdpSocket *m_udpSocket =nullptr;
    SecureFileUploader *m_uploader;
    // 初始化界面
    void initUI();
    // 创建 ssh
    Ssh * ssh = nullptr;
    // 字体
    QFont font;
    // 主机
    QLabel * hostLabel;
    QLineEdit * hostLineEdit;
    // 端口
    QLabel * portLabel;
    QLineEdit * portLineEdit;
    // 用户名
    QLabel * userNameLabel;
    QLineEdit * userNameLineEdit;
    // 密码
    QLabel * passwdLabel;
    QLineEdit * passwdLineEdit;
    // 连接状态
    QLabel * linkStateLabel;
    // 快速连接
    QPushButton * linkBtn;
    QPushButton * PushBtn;
    QPushButton * PullBtn;


    // 指令
    QLabel * cmdLabel;
    // 指令
    QLineEdit * cmdLineEdit;
    //清空
    QPushButton * clearBtn;
    // 输出信息
    QTextBrowser * textBrowser;

    QTableWidget * tableWidget;


    QStringList m_SShPathList;

    bool connectPullYAML = false;//ssh连接成功拉取YMAL

    QProgressDialog *progressDialog;

};

#endif // TM_SSHCONNECTWGT_H
